{extend name="admin@base"/}

{block name='second_menu'}
{notempty name="$menu[2]"}
<ul class="layui-nav nc-nav">
	{foreach name="$menu[2]" item="second_menu"}
	<li class="layui-nav-item {$second_menu['selected']}">
		<a href="{$second_menu['url']}" {$second_menu['target']}>{$second_menu['title']}</a>
	</li>
	{/foreach}
</ul>
{/notempty}
{/block}
{block name='crumbs'}{/block}
{block name="main"}
<style>
.icon-box {display: inline-block;width: 25px;margin-right: 10px;}
.icon-box .icon {width: 100%;}
</style>

<table id="sms_list" class="layui-table"></table>
<script type="text/html" id="title">
	<p class="icon-box">
		<img class="icon" src="{{d.info.icon}}"/>
	</p>
	<span>{{d.info.title}}</span>
</script>
<script type="text/html" id="status">
	<input type="checkbox" name="status"  lay-skin="switch" value="{{d.config.name}}" lay-filter="status" lay-text="" {{ d.config.status==1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="operation">
	<a href="{{ d.info.url }}" class="default" lay-event="edit">编辑</a>
</script>
{/block}

{block name="script"}
<script>
var table = new Table({
	elem: '#sms_list',
	url: '{:addon_url("sms://admin/config/index")}',
	cols: [
		[{
			field: 'title',
			width: '50%',
			title: '短信平台',
			templet: '#title'
		}, {
			title: '状态',
			toolbar: '#status',
		}, {
			title: '操作',
			toolbar: '#operation',
            align: 'right'
		}]
	],
	page : false
});

layui.use(['form'], function(){
	var form = layui.form;
	form.on('switch(status)', function(data){
		var name = data.value;
		var status = data.elem.checked ? 1 : 0;
		$.ajax({
			type : "post",
			url : '{:addon_url("sms://admin/config/setconfigstatus")}',
			dataType : "JSON",
			data : {
				'status' : status,
				'name' : name
			},
			success : function(res) {
				table.reload({
						page : false
					});
				layer.msg(res.message);
			}
		});
		return false;
	}); 
	
});
</script>
{/block}